﻿using System.Web.Mvc;
using System.Web.Routing;
using EPiMVC.Routing;
using EPiServer.Core;

namespace EPiMVC
{
    public static class UrlExtensions
    {
        public static string PageUrl(this UrlHelper helper, PageReference pageReference)
        {
            RouteValueDictionary values = new RouteValueDictionary();
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return helper.RouteUrl(values);
        }

        public static string PageUrl(this UrlHelper helper, PageReference pageReference, object routeValues)
        {
            RouteValueDictionary values = new RouteValueDictionary(routeValues);
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return helper.RouteUrl(values);
        }

        public static string PageUrl(this UrlHelper helper, string action, PageReference pageReference)
        {
            RouteValueDictionary values = new RouteValueDictionary();
            values.Add("action", action);
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return helper.RouteUrl(values);
        }

        public static string PageUrl(this UrlHelper helper, string action, PageReference pageReference, object routeValues)
        {
            RouteValueDictionary values = new RouteValueDictionary(routeValues);
            values.Add("action", action);
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return helper.RouteUrl(values);
        }
    }
}
